﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Wap/Shop/ShopSite.Master" AutoEventWireup="true"
    CodeBehind="OrderDetail.aspx.cs" Inherits="ZLCMS.Web.Wap.Shop.OrderDetail" %>

<%@ Register Src="Footer.ascx" TagName="Footer" TagPrefix="uc1" %>
<%@ Import Namespace="ZLCMS.Business.Util" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .details_btn
        {
            margin: 0em 0.5em 10px;
        }
        .details_btn li
        {
            float: left;
            width: 32%;
            margin-right: 2%;
        }
        .details_btn li:nth-child(2)
        {
            float: left;
            width: 32%;
        }
        .details_btn li:last-child
        {
            width: 32%;
            margin-right: 0;
        }
        .order_ok
        {
            background: #fff;
        }
        .order_ok .title span
        {
            color: #999;
            float: right;
        }
        .order_details .box p.elapsedtips
        {
            color: #f9384d;
            font-size: 12px;
            line-height: 16px;
        }
        .footer_list
        {
            overflow: hidden;
            padding: 0 5px;
        }
        .footer_list li
        {
            float: right;
            height: 45px;
        }
        .footer_list li a.btn
        {
            padding: 3px 10px;
            font-size: 12px;
            display: inline-block;
            color: #fff;
            font-weight: normal;
            background: #f9384d;
            border-radius: 3px;
            margin: 10px 5px 0 0;
            width: 68px;
        }
        
        #packagePage .refundTop
        {
            position: relative;
            background: #fff;
            text-align: center;
            color: #333;
            line-height: 40px;
            border-bottom: 1px solid #eee;
        }
        #packagePage .refundTop img
        {
            position: absolute;
            left: 10px;
            height: 15px;
            top: 12px;
        }
        .giftList .order_okbox .right
        {
            width: 100%;
        }
        .giftListContainer
        {
            margin-bottom: 50px;
        }
        span.gistGift
        {
            font-size: 13px;
            margin-left: 20px;
        }
        .box-e {
            margin: 0 !important;
            border-top: 1px dashed #eee !important;
            border-bottom: 1px dashed #eee !important;
        }
        .box-e p, .box-e span {
            color: #999 !important;
        }
    </style>
    <title>订单详情</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="pages" runat="server">
    <!--S page -->
    <div data-role="page" id="mypage">
        <!--S header -->
        <div data-role="header">
        </div>
        <!--E header -->
        <!--S content -->
        <div role="main" class="ui-content">
            <div class="refundTop">
                <a href="/wap/shop/OrderList.aspx" data-ajax="false">
                    <img src="images/arrowLeftCom.png" /></a> 订单详情
            </div>
            <!--s order_details-->
            <div class="order_details loaderHandler">
                <!--s box-->
                <div class="box">
                    <p>
                        订单编号：<span prop="Data.OrderNo"></span></p>
                    <p>
                        下单时间：<span prop="Data.OrderTime"></span></p>
                    <p>
                        支付方式：<span prop="Data.PaymentName"></span></p>
                    <p>
                        订单状态：<span class="statusText">-</span></p>
                    <p>
                        商品总价：<span>￥</span><span prop="Data.ProducctFee"></span></p>
                    <p class="TitleDiscountFee">
                        优惠金额：<span>￥</span><span prop="Data.DiscountFee"></span></p>
                    <p class="TitleShipPrice">
                        实付邮费：<span>￥</span><span prop="Data.ShipPrice"></span></p>
                    <p>
                        实付金额：<span>￥</span><span prop="Data.TotalPrice"></span></p>
                    <%--   <p class="shippingnotips" style="display:none">物流单号：<span prop="Data.ShippingNo">-</span> （<span prop="Data.ShippingType">-</span>）</p>--%>
                    <p class="elapsedtips" prop="Data.ElapsedTips">
                    </p>
                </div>
                <!--e box-->
                <!--s btn-->
                <ul class="details_btn actionHtml" style="display: none;">
                </ul>
                <!--e btn-->
                <!--s order_messages-->
                <div class="order_messages" id="orderAddr">
                    <p>
                        收货地址：<span prop="Data.ReceiverProvince"></span><span prop="Data.ReceiverCity"></span><span
                            prop="Data.ReceiverAddress"></span></p>
                    <p>
                        收&nbsp;&nbsp;货&nbsp;&nbsp;人：<span prop="Data.ReceiverName"></span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
                            prop="Data.ReceiverPhone"></span></p>
                </div>
                <!--e order_messages-->
                <!--s order_ok-->
                <div class="order_ok productListContainer" style="display: none">
                    <div class="title">
                        商品信息</div>
                    <div class="productList">
                    </div>
                </div>
                <div class="order_ok giftListContainer" style="display: none">
                    <div class="title">
                        赠品信息</div>
                    <div class="giftList">
                    </div>
                </div>
                <!--e order_ok-->
                <!--s parcel-->
                <div class="parcel packageListContainer" style="display: none">
                </div>
                <!--e parcel-->
                
            </div>
            <!--e order_details-->
        </div>
        <!--E content -->
        <!--S footer -->
        <div data-role="footer" data-position="fixed" data-tap-toggle="false">
            <ul class="footer_list actionHtml">
                <%--  <li><a href="#">再次购买</a></li>
            <li><a href="#">发表评价</a></li>--%>
            </ul>
            <%--<uc1:Footer ID="Footer1" runat="server" MenuId="M"  />   --%>
        </div>
        <!--E footer -->
    </div>
    <!--E page -->
    <!--E AddressList -->
    <div data-role="page" id="packagePage">
        <div role="main" class="ui-content">
            <div class="refundTop">
                <a href="javascript:void(0)" onclick="history.back()" data-ajax="false">
                    <img src="images/arrowLeftCom.png" /></a> 包裹明细
            </div>
            <div style="" class="order_ok packageContainer">
            </div>
        </div>
    </div>
    <!--E AddressList -->
    <script src="js/order.js?v=0615" type="text/javascript"></script>
    <script src="/wap/lib/common/loaderHandler.js" type="text/javascript"></script>
    <script type="text/javascript">
    var orderDetailData;

    $(function () {
        var handler = $('.loaderHandler').loaderHandler();
        handler.initialize({
            command: 'Member.LoadOrderDetail',
            parameter: { MemberAccount: '<%=CurrentMemberAccount %>', OrderNo: '<%=Request["no"] %>' },
            beforeHandleResult: function (result, totalCount, container) {
                if (result.Data.DiscountFee == 0) {
                    $('.TitleDiscountFee').hide();
                }
                if (result.Data.ShipPrice == 0) {
                    $('.TitleShipPrice').hide();
                }
                var statusText = '无效';
                var actionHtml = '';

                if (result.Data.CancelStatus == '1') {
                    statusText = '[已取消]';
                    if (result.Data.PayStatus != '0') {
                        result.Data.ElapsedTips = '本订单费用将在3-5工作日通过微信原路返回至您的支付帐户';
                    }
                } else if (result.Data.PayStatus == '0' && result.Data.CancelStatus == '0') {
                    statusText = '[待支付]';

                    var orderTime = new Date(Date.parse(result.Data.OrderTime.replace(/-/g, "/")));
                    var cancelTime = new Date();
                    cancelTime.setTime(orderTime.getTime() + 1000 * parseInt('<%=ParamKit.GetValue("SystemConfig", "OrderTimeout", "60") %>') * 60);

                    result.Data.ElapsedTips = '本订单将于[' + cancelTime.Format('yyyy-MM-dd hh:mm:ss') + ']取消，请及时支付';

                    //取消，去支付
                    actionHtml = '<li><a href="#" onclick="payOrder($(this),\'{MemberAccount}\', \'{PaymentNo}\')" class="btn">去支付</a></li><li><a href="#" class="btn" onclick="cancelOrder($(this),\'{MemberAccount}\', \'{OrderNo}\');">取消</a></li>'
                        .format({ MemberAccount: '<%=CurrentMemberAccount %>', PaymentNo: result.Data.PaymentNo, OrderNo: result.Data.OrderNo });
                } else if (result.Data.PayStatus != '0' && result.Data.CancelStatus == '0' && result.Data.FinishedStatus == '0') {
                    if (result.Data.ConfirmedStatus == '0') {
                        statusText = '[已支付]';
                        //可以取消订单
                        if (result.Data.SplitStatus == "9") {
                            actionHtml = '<li><a href="#" class="btn" onclick="cancelOrder($(this), \'{MemberAccount}\', \'{OrderNo}\');">取消</a></li>'
                            .format({ MemberAccount: '<%=CurrentMemberAccount %>', OrderNo: result.Data.OrderNo });
                        }
                    } else if (result.Data.ShippingStatus == '0') {
                        statusText = '[配货中]';
                        actionHtml = '<li><a href="/wap/shop/SubmitReturnApply.aspx?no={OrderNo}" class="btn" data-ajax="false" >申请售后</a></li><li><a href="/wap/shop/KFList.aspx?no={OrderNo}" class="btn wuliu" data-ajax="false" >联系客服</a></li>'
                        .format({ MemberAccount: '<%=CurrentMemberAccount %>', OrderNo: result.Data.OrderNo });

                        var dnow = new Date();
                        var dorder = new Date(Date.parse(result.Data.OrderTime.replace(/\-/g, "\/")));
                        if ((dnow - dorder) > 86400000) {
                            result.Data.ElapsedTips = '我们将尽快发货，请留意物流信息';
                        }
                    } else if (result.Data.ShippingStatus == '1') {
                        statusText = '[已发货]';
                        result.Data.ElapsedTips = '物流信息可能同步较慢，如不能查询信息，请稍后再试';
                        actionHtml = '<li><a href="/wap/shop/ReturnablesList.aspx?no={OrderNo}" class="btn" data-ajax="false" >申请售后</a></li>'
                        .format({ MemberAccount: '<%=CurrentMemberAccount %>', OrderNo: result.Data.OrderNo, ShippingType: result.Data.ShippingType, ShippingNo: result.Data.ShippingNo });
                    }
                } else if (result.Data.CancelStatus == '0' && result.Data.FinishedStatus == '1') {
                    statusText = '[已完成]';
                    result.Data.ElapsedTips = '如收货后发现产品质量问题，请立即提交售后，或联系客服';
                    if (result.Data.CommentStatus == '1') {
                        //<li><a href="#" class="btn" onclick="deleteOrder($(this), \'{MemberAccount}\', \'{OrderNo}\');">删除</a></li>  订单不需要删除
                        actionHtml = '<li><a data-ajax="false" href="CommentCenter.aspx" class="btn">马上评价</a></li><li><a href="/wap/shop/ReturnablesList.aspx?no={OrderNo}" class="btn" data-ajax="false" >申请售后</a></li><li><a href="/wap/shop/KFList.aspx?no={OrderNo}" class="btn wuliu" data-ajax="false" >联系客服</a></li>'
                            .format({ MemberAccount: '<%=CurrentMemberAccount %>', OrderNo: result.Data.OrderNo });
                    } else {
                        //todo:评论的状态为-9时，评价显示不正确，暂时屏蔽
                        //<li><a data-ajax="false" href="CommentHistory.aspx?ono={OrderNo}" class="btn">查看评价</a></li>
                        //<li><a href="#" class="btn" onclick="deleteOrder($(this), \'{MemberAccount}\', \'{OrderNo}\');">删除</a></li>
                        actionHtml = '<li><a href="/wap/shop/ReturnablesList.aspx?no={OrderNo}" class="btn" data-ajax="false" >申请售后</a></li><li><a href="/wap/shop/KFList.aspx?no={OrderNo}" class="btn wuliu" data-ajax="false" >联系客服</a>'
                            .format({ MemberAccount: '<%=CurrentMemberAccount %>', OrderNo: result.Data.OrderNo });
                        if (result.Data.AppendStatus == "1" && result.Data.CommentStatus == "0") {
                            actionHtml += '<a data-ajax="false" href="CommentCenter.aspx?ono={OrderNo}&cs=1" class="btn">追评</a>'
                            .format({ OrderNo: result.Data.OrderNo });
                        }
                        actionHtml += "</li>";
                    }
                }

                if (result.Data.ShippingStatus == '1' && result.Data.ShippingNo != '') {
                    $('.shippingnotips').show();
                }

                //不是实物订单，无需显示地址信息
                if (result.Data.Kind != 'shop') {
                    $('#orderAddr').hide();
                }


                $('.statusText').text(statusText);


                try {
                    var actionList = $.parseJSON(result.Data.OrderActions);
                    $(actionList).each(function () {
                        actionHtml = '<li><a data-ajax="false" href="{Url}" class="btn">{Name}</a></li>'.format(this)
                        + actionHtml;
                    });
                } catch (e) { }
                $('.actionHtml').html(actionHtml);

                if (result.Data.PackageStatus == '1') {
                    //显示包裹信息
                    var itemTemp = '<div>' +
                     '<p>' +
                         '<span>{Title}</span><span>{StatusText}</span>' +
                     '</p>' +
                     '<div class="img_list" onclick="showPackageDetail(\'{OrderNo}\',\'{PackageNo}\');">' +
                         '<ul>{ProductHtml}</ul>' +
                         '<p>' +
                             '共<i>{ProductCounter}</i>件 <img src="/wap/shop/images/usercenter_righticon.png" alt="Alternate Text" />' +
                         '</p>' +
                     '</div>{GiftHtml}' +
                     '{Baoguoxx}' + 
                     '{OptionHtml}' +
                 '</div>';
                    var gift = '<div class="img_list">' +
                     '<ul><li><span class="gistGift">{ProductName}</span></li></ul>' +
                     '</div>'; //共<i>{Counter}</i>件
                    $(result.Data.PackageList).each(function () {
                        //                        this.ThumbnailImg = firstFilePath(this.ThumbnailImg);
                        //                        var skuData = $.parseJSON(this.SkuParamCode);
                        //                        var skuHtml = '';
                        //                        $(skuData).each(function () { skuHtml += '<span>' + this.ItemName + '</span>'; });
                        //                        this.SkuHtml = skuHtml;
                        this.GiftHtml = ""
                        if (this.GiftList != "[]" && this.GiftList != null) {
                            var GifthtmlTemp = "";
                            $($.parseJSON(result.Data.GiftList)).each(function () {
                                if (this.DeptCode) {
                                    $(this.GiftList).each(function () {
                                        if (this.Counter > 0) {
                                            this.ProductName = this.ProductName + "×" + this.Counter;
                                        }
                                        GifthtmlTemp += gift.format(this);
                                    });
                                } else {
                                    //                                $(this.GiftList).each(function () {
                                    //                            this.ThumbnailImg = firstFilePath(this.ThumbnailImg);
                                    //                            var skuData = $.parseJSON(this.SkuParamCode);
                                    //                            var skuHtml = '';
                                    //                            $(skuData).each(function () { skuHtml += '<span>' + this.ItemName + '</span>'; });
                                    //                            this.SkuHtml = skuHtml;
                                    if (this.Counter > 0) {
                                        this.ProductName = this.ProductName + "×" + this.Counter;
                                    }
                                    GifthtmlTemp += gift.format(this);
                                    //                                })
                                }
                            })
                            this.GiftHtml = "<p><font>赠品</font></p>" + GifthtmlTemp;
                        }
                        this.OptionHtml = '';
                        if (this.CancelStatus == 1) {
                            this.StatusText = '已取消';
                        } else if (this.ShipStatus == 0) {
                            this.StatusText = '配货中';
                        } else if (this.ShipStatus == 1 && this.FinishStatus == 0) {
                            this.OptionHtml = ('<div class="button"><a onclick="finishPackage($(this),\'\', \'{pno}\')">签收</a> <a onclick="checkShipping(\'{stype}\',\'{sno}\')">查询物流</a></div>'
                            .format({ stype: this.ShipType, sno: this.ShipNo, pno: this.PackageNo }));
                            this.StatusText = '已发货';
                        } else if (this.FinishStatus == 1) {
                            this.OptionHtml = ('<div class="button"><a onclick="checkShipping(\'{stype}\',\'{sno}\')">查询物流</a></div>'
                            .format({ stype: this.ShipType, sno: this.ShipNo }));
                            this.StatusText = '已签收';
                        }

                        var productHtml = '';
                        var counter = 0;
                        $(this.PackageProduct).each(function () {
                            productHtml += '<li><img src="{Url}" alt="{ProductName}"/></li>'.format({ ProductNo: this.ProductNo, ProductName: this.ProductName, Url: firstFilePath(this.ProductImage) });
                            counter += this.Counter;
                        });
                        this.ProductHtml = productHtml;
                        this.ProductCounter = counter;

                        this.Baoguoxx = '<div class="box box-e"><p>运输编号：<span>{ShipNo}</span></p><p>运输方式：<span>{ShippingName}</span></p><p></div>'.format(this)

                        $('.packageListContainer').append(itemTemp.format(this));

                    });

                    //控制包裹和产品的可见性
                    $('.productListContainer').hide();
                    $('.giftListContainer').hide();
                    $('.packageListContainer').show();
                } else {
                    //显示产品列表
                    var itemTemp = '<div class="order_okbox"><a href="ProductDetail.aspx?no={ProductNo}" data-ajax="false">' +
                	'<div class="left"><img src="{ThumbnailImg}"></div>' +
                    '<div class="right">' +
                    	'<div class="text">' +
                        '{ProductName}' +
                        '</div>' +
                        '<p>{SkuHtml}</p>' +
                        '<p>￥{SalePrice} * {Counter}件</p>' +
                    '</div></a>' +
                    '<div class="clear"></div>' +
                '</div>';
                    $(result.Data.ProductList).each(function () {
                        this.ThumbnailImg = firstFilePath(this.ThumbnailImg);
                        var skuData = $.parseJSON(this.SkuParamCode);
                        var skuHtml = '';
                        $(skuData).each(function () { skuHtml += '<span>' + this.ItemName + '</span>'; });
                        this.SkuHtml = skuHtml;
                        $('.productList').append(itemTemp.format(this));
                    });
                    var giftTemp = '<div class="order_okbox"><a href="#" data-ajax="false">' +
                    //                	'<div class="left"><img src="{ThumbnailImg}"></div>' +
                    '<div class="right">' +
                    	'<div class="text">' +
                        '{ProductName} ' + //* {Counter}件
                        '</div>' +
                    //                        '<p>{SkuHtml}</p>' +
                    //                        '<p>￥{SalePrice} * {Counter}件</p>' +
                    '</div></a>' +
                    '<div class="clear"></div>' +
                '</div>';
                    var giftlist = $.parseJSON(result.Data.GiftList);
                    if (giftlist && giftlist != "") {
                        $('.giftListContainer').show();
                        var productName = ""
                        $(giftlist).each(function () {
                            //                            $(this.GiftList).each(function () {
                            //                            this.ThumbnailImg = firstFilePath(this.ThumbnailImg);
                            //                            var skuData = $.parseJSON(this.SkuParamCode);
                            //                            var skuHtml = '';
                            //                            $(skuData).each(function () { skuHtml += '<span>' + this.ItemName + '</span>'; });
                            //                            this.SkuHtml = skuHtml;
                            if (this.Counter > 0) {
                                productName += this.ProductName + "×" + this.Counter + "&nbsp;&nbsp;";
                            } else {
                                productName += this.ProductName + "&nbsp;&nbsp;";
                            }
                            // productName += this.ProductName + "&nbsp;&nbsp;";
                            //                            })
                        })
                        $('.giftList').html(giftTemp.format({ ProductName: productName }));

                    }
                    //控制包裹和产品的可见性
                    $('.productListContainer').show();
                    $('.packageListContainer').hide();
                }
                orderDetailData = result;
            }
        });
        handler.load();
    });
    $('[prop="Data.DiscountFee"]').bind('valuechange', function (event, param) {
        if (param.value >= 0) {
            $(this).text(param.value);
        }
        if (param.value < 0) {
            $(this).parent("p").html('附加金额：<span>￥</span><span prop="Data.DiscountFee">' + Math.abs(param.value) + '</span>');
        }
        $(event.target).triggerHandler('valuechanged', param);
        return false;
    });
    //点击选择地址，跳转地址列表
    function showPackageDetail(on, pn) {
        //初始化数据
        var thisDetail;

        $(orderDetailData.Data.PackageList).each(function () {
            if (this.OrderNo == on && this.PackageNo == pn) {
                thisDetail = this;
                return false;
            }
        });

        if (thisDetail != null) {
            //显示产品列表
            $('.packageContainer').empty();
            var itemTemp = '<div class="order_okbox"><a href="ProductDetail.aspx?no={ProductNo}" data-ajax="false">' +
                	'<div class="left"><img src="{ProductImage}"></div>' +
                    '<div class="right">' +
                    	'<div class="text">' +
                        '{ProductName}' +
                        '</div>' +
                        '<p>{SkuHtml}</p>' +
                        '<p>{Counter}件</p>' +
                    '</div></a>' +
                    '<div class="clear"></div>' +
                '</div>';
            $(thisDetail.PackageProduct).each(function () {
                this.ProductImage = firstFilePath(this.ProductImage);
                var skuData = $.parseJSON(this.SkuData);
                var skuHtml = '';
                $(skuData).each(function () { skuHtml += '<span>' + this.ItemName + '</span>'; });
                this.SkuHtml = skuHtml;
                $('.packageContainer').append(itemTemp.format(this));
            });
            
            jQuery.mobile.changePage($('#packagePage'));
        } 
    }
 
    </script>
</asp:Content>

